/**
 * weather now
 * url: http://localhost:3002/m1/wea/now?cityid=101020100
 */
import { httpFetch } from '../../utils/req'

const staticData = {
  code: 0,
  msg: '失败',
  data: {},
}

const appsecret = 'Pf48jMz8'
const appid = '75437651'

export default (query, request) => {
  let { cityid } = query
  if (!cityid) cityid = ''
  return new Promise((resolve, reject) => {
    httpFetch(
      `https://www.yiketianqi.com/free/day?appid=${appid}&appsecret=${appsecret}&unescape=1&cityid=${cityid}`,
      {
        method: 'get',
        headers: {},
      }
    )
      .promise.then((res) => {
        if (res.statusCode === 200) {
          resolve(res.body)
        } else {
          resolve(staticData)
        }
      })
      .catch((e) => {
        reject(e)
      })
  })
}
